package com.qdxht.dispenser.ui.activity.main;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import com.hjq.toast.ToastUtils;
import com.qdxht.dispenser.BuildConfig;
import com.qdxht.dispenser.base.BaseActivity;
import com.qdxht.dispenser.base.manager.ActivityManager;
import com.qdxht.dispenser.databinding.ActivitySettingsBinding;
import com.qdxht.dispenser.utils.DeviceIdUtil;

/**
 * 设置页面
 */
public class SettingsActivity extends BaseActivity<ActivitySettingsBinding> {

    public static void start(Context context) {
        Intent intent = new Intent(context, SettingsActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected ActivitySettingsBinding getBinding() {
        return ActivitySettingsBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        // 出货设置
        binding.rlDeliverySettings.setOnClickListener(v -> {
            DeliverySettingsActivity.start(this);
        });

        // 二维码设置
        binding.rlQrcodeSettings.setOnClickListener(v -> {
            QRCodeSettingsActivity.start(this);
        });

        // 参数配置
        binding.rlParamSettings.setOnClickListener(v -> {
            ParamSettingsActivity.start(this);
        });

        // 系统设置
        binding.rlSystemSettings.setOnClickListener(v -> {
            // 打开系统设置页面
            startActivity(new Intent(Settings.ACTION_SETTINGS));
        });

        // 退出按钮
        binding.btnLogout.setOnClickListener(v -> {
            showExitConfirmDialog();
        });

    }

    @Override
    protected void initData() {
        String androidId = DeviceIdUtil.getAndroidId(this);
        // 主板信息
        binding.tvHardwareVersion.setText(androidId);// 设置版本信息
        binding.tvAppVersion.setText("v "+BuildConfig.VERSION_NAME);
    }

    /**
     * 显示退出确认对话框
     */
    private void showExitConfirmDialog() {
        new AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("确定要退出应用吗？")
                .setPositiveButton("确定", (dialog, which) -> {
                    // TODO: 执行退出前的清理工作
                    ActivityManager.getInstance().finishAllActivities();
                    android.os.Process.killProcess(android.os.Process.myPid());
                })
                .setNegativeButton("取消", null)
                .show();
    }
} 